import datagraph.bundle.PrintName
import datagraph.core.Bundle

object TestUpickle extends App {

  import upickle.default._

  sealed trait IntOrTuple

  import upickle.default.{ReadWriter => RW, macroRW}

  object IntOrTuple {

    implicit val rw: RW[IntOrTuple] = RW.merge(IntThing.rw, TupleThing.rw)
  }

  case class IntThing(i: Int) extends IntOrTuple

  object IntThing {
    implicit val rw: RW[IntThing] = macroRW
  }

  case class TupleThing(name: String, t: (Int, Int)) extends IntOrTuple

  object TupleThing {
    implicit val rw: RW[TupleThing] = macroRW
  }

  val t = TupleThing("naeem", (1, 2))
  println(write(t))

  case class Test(s: String)

  //println(writeJs(Test("d")))


  case class CacheAnyBundleLink(cur: Bundle, upstream: Seq[CacheAnyBundleLink] = Nil)



  import datagraph.bundle._
  //Read
  //PrintAndOutput PrintAndOutput
  implicit val bundleRW:RW[Bundle]=RW.merge(Read.rw,PrintAndOutput.rw)
 implicit val linkRW:RW[CacheAnyBundleLink]= upickle.default.readwriter[String].bimap[CacheAnyBundleLink](
    t=> s"{'cur':${write(t.cur)},'up':${write(t.upstream)}" ,
    t=> ???
  )
  //upickle.default.writer[CacheAnyBundleLink].

  println(write(CacheAnyBundleLink(PrintAndOutput(), Seq(CacheAnyBundleLink(Read("sss"))))))


}
